// component/SStop/sstop.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    multipleSlots: true
  },

  properties: {
    // 弹窗标题    
    manName: {            // 属性名
      type: String,     // 类型（必填），目前接受的类型包括：String, Number, Boolean, Object, Array, null（表示任意类型）
      value: '李慧'     // 属性初始值（可选），如果未指定则会根据类型选择一个
    },
    avatarUrl: {
      type: String,
      value: "../../img/man.png"
    },
    taskNum: {
      type: String,
      value: '0'
    },
    collectNum: {
      type: String,
      value: '0'
    },
    clientNum: {
      type: String,
      value: '0'
    },
    departmentList: {
      type: Array,
      value: new Array()
    },
    isHidden: {
      type: Boolean,
      value: false
    },//是否显示tab切换
    toDoNumSlt: {
      type: Boolean,
      value: true
    },
    dynamicStateSlt: {
      type: Boolean,
      value: true
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isSelected: false,
    showDepartment: false,
    job: '客户开发',
    flagName: "lawsuitInvest",//执行("enforce"), 诉讼("lawsuit"),市场部("lawsuitInvest")
    menuTab: "task",//任务列表("task"),//关注("collect"),客户列表("client"),律师协助("lawyerHelp")
    toDoNumSlt: true,
    attentionNumSlt: false,
    dynamicStateSlt: false,
    lawyerHelpSlt:false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    avatartap: function () {
      wx.showActionSheet({
        itemList: ['退出登录'],
        success: function (res) {
          console.log(res.tapIndex)
          if (res.tapIndex == 0) {
            wx.clearStorageSync();
            app.globalData.userInfo = null;
            app.globalData.loginUserInfo = '';
            wx.redirectTo({
              url: '../../index/index'
            })
          }
        },
        fail: function (res) {
          console.log(res.errMsg)
        }
      })
    },
    // 去任务列表
    goIndex() {
      this.setData({
        toDoNumSlt: true,
        attentionNumSlt: false,
        dynamicStateSlt: false,
        lawyerHelpSlt: false,
        ShareDocSlt: false,
      });

      //触发待办列表回调
      this.triggerEvent("goTaskPage", this.data.flagName + "|" + "task")
    },

    //去我的收藏
    goAttention: function () {
      this.setData({
        toDoNumSlt: false,
        attentionNumSlt: true,
        dynamicStateSlt: false,
        lawyerHelpSlt: false,
        ShareDocSlt: false,
      });
      //触发我的关注
      this.triggerEvent("goCollectPage", this.data.flagName + "|" + "collect");
      // wx.redirectTo({
      //   url: '../../SuSong/collection/collection',
      // })
    },

    //去客户列表
    goState() {
      this.setData({
        toDoNumSlt: false,
        attentionNumSlt: false,
        dynamicStateSlt: true,
        lawyerHelpSlt: false,
        ShareDocSlt: false,
      });
      //触发我的关注
      this.triggerEvent("goClientPage", this.data.flagName + "|" + "client");
      // wx.redirectTo({
      //   url: '../../SuSong/clientList/clientList',
      // })
    },

    //去律师协助
    goMonitoring() {
      this.setData({
        toDoNumSlt: false,
        attentionNumSlt: false,
        dynamicStateSlt: false,
        lawyerHelpSlt: true,
        ShareDocSlt: false,
      });
      // wx.redirectTo({
      //   url: '../../SuSong/counsel/counsel' 
      // })
      //触发我的关注
      this.triggerEvent("golawyerHelpPage", this.data.flagName + "|" + "lawyerHelp");
    },
    //去文档库
    goShareDoc: function () {
      this.setData({
        toDoNumSlt: false,
        attentionNumSlt: false,
        dynamicStateSlt: false,
        lawyerHelpSlt:false,
        ShareDocSlt: true,
      });
      //触发我的关注
      this.triggerEvent("goShareDoc", this.data.flagName + "|" + "ShareDoc");
    },
    selectTask(e) {
      let array = this.data.taskList;
      let index = e.currentTarget.dataset.index;
      for (let i = 0; i < array.length; i++) {
        array[i].slt = ''
      }
      array[index].slt = 'border-bottom:1px solid #222';

      this.setData({
        taskList: array
      })
    },
    isShowDepartment() {
      let jobArray = this.data.departmentList;
      let jobSlt = this.data.job;
      if (jobArray.length <= 1) {
        return
      }
      if (!this.data.showDepartment) {
        for (let i = 0; i < jobArray.length; i++) {
          jobArray[i].selected = false;
          if (jobArray[i].name == jobSlt) {
            jobArray[i].selected = true;
            // console.log('===========一样了')
          }
        }
        this.setData({
          showDepartment: true,
          departmentList: jobArray
        })
      } else {
        this.setData({
          showDepartment: false
        })
      }
    },

    departmentCon: function () {
      this.setData({
        showDepartment: false,
      })
    },
    //选中部门选择
    selectJob(e) {
      app.globalData.listRefresh = {};
      let jobArray = this.data.departmentList;
      let index = e.currentTarget.dataset.index;
      let flagName = jobArray[index].flagName;
      wx.setStorageSync("flagName", flagName);
      console.log('flagName', flagName)
      if (flagName == "lawsuit" || flagName =='enforce'){
        this.setData({
          showDepartment: false
        })
        wx.redirectTo({
          url: '../../syIndex/syIndex?flagName=' + flagName
        })
      } else if (flagName == 'nonLitigation') {
        this.setData({
          showDepartment: false
        })
        wx.redirectTo({
          url: '../../FeiSu/fsIndex/fsIndex?flagName=' + flagName
        })
      } else if (flagName == "caseTrack") {
        this.setData({
          showDepartment: false
        })
        wx.redirectTo({
          url: '../../Case/caseIndex/caseIndex?flagName=' + flagName
        })
      }else{
        this.setData({
          job: jobArray[index].name,
          flagName: flagName,
          showDepartment: false,
          toDoNumSlt: true,
          attentionNumSlt: false,
          dynamicStateSlt: false,
        })
        //触发取消回调
        this.triggerEvent("selectDepart", flagName)
      }
    }
  }
})
